import cn.ecut.dao.UserMapper;
import cn.ecut.pojo.User;
import cn.ecut.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

/**
 * @Author ruanxin
 */
public class Mytest {
    Logger logger=Logger.getLogger(Mytest.class);

    @Test
    public void test01(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.queryUserById(1);
        logger.info(user);
        logger.info("======================");

        mapper.updateUser(new User(2, "xc", "333"));
        logger.info("修改完毕");
        User user2 = mapper.queryUserById(1);
        logger.info(user2);
        logger.info("======================");
        User user3 = mapper.queryUserById(1);
        logger.info(user3);
        logger.info(user==user2);

        sqlSession.close();
    }

    @Test
    public void test02(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        SqlSession sqlSession2 = MybatisUtils.getSqlSession();

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        UserMapper mapper2 = sqlSession2.getMapper(UserMapper.class);

        User user = mapper.queryUserById(1);
        sqlSession.close();
        User user1 = mapper2.queryUserById(1);
        logger.info(user==user1);

        sqlSession2.close();

    }

}
